<?php
class DB
{
	public function fetchAll($sql){
		global $db;
		$query = $db->prepare($sql);
		$query->execute();
		$result=$query->fetchAll();
		$error = $query->errorInfo();
		if($result){
			return $result;
		}
		else{
			print_r($error[2]);
			return false;
		}		
	}
	
	public function fetchRow($sql){
		global $db;
		$query = $db->prepare($sql);
		$query->execute();
		$result = $query->fetch(PDO::FETCH_ASSOC);
		$error = $query->errorInfo();
		if($result){
			return $result;
		}
		else{
			print_r($error[2]);
			return false;
		}				

	}
	
	public function updateDB($sql="",$field=""){
		global $db;
		$query = $db->prepare($sql);
		$result = $query->execute($field);
		$error = $query->errorInfo();
		
		if($result){
			return $result;
		}
		else{
			print_r($error[2]);
			return false;
		}		
		
	}
	
	public function count($sql){
		global $db;
		$query = $db->prepare($sql);
		$query->execute();
		$result = $query->fetchColumn();
		if($result){
			return $result;
		}
		else{
			print_r($error[2]);
			return false;
		}		
		
	}
}
?>